<?php
	require_once('functions.php');
	
	// EMPLOYEE FUNCTIONS
	function GetEmployees(){
		$conn = GetConnection();
		return $results = $conn -> query('SELECT * FROM WSP2012_Employee');
	}
	
	function GetEmployee($id){
		$conn= GetConnection();
		$sql = "SELECT * FROM WSP2012_Employee WHERE employee_id=$id ";
		$results = $conn -> query($sql);
		$row = $results -> fetch_assoc();
		$conn -> close();
		return $row;
	}
	
	function SaveEmployee($row){
		$conn = GetConnection();
		$row2 = EscapeRow($row, $conn);
		$sql = "UPDATE `WSP2012_Employee` " 
			.	"Set users_id='$row2[users_id]', updated_at='$row2[updated_at]', hire_date='$row2[hire_date]', payperhour='$row2[payperhour]' "
			.	"WHERE employee_id='$row2[id]' ";
		$results = $conn -> query($sql);
		$error = $conn -> error;
		$conn -> close();
		
		return $error == '' ? true : array('SQL Error' => $error);	
	}
	
	function CreateEmployee($row){
		$conn = GetConnection();
		$row2 = EscapeRow($row, $conn);
		$sql = "INSERT INTO `WSP2012_Employee` "
			.		"(employee_id, users_id, created_at, updated_at, hire_date, payperhour) "
			.		"VALUES ('$row2[employee_id]', '$row2[users_id]', '$row2[created_at]', '$row2[updated_at]', '$row2[hire_date]', '$row2[payperhour]') ";
		$results = $conn -> query($sql);
		$error = $conn -> error;
		$conn -> close();	
		
		return $error == '' ? true : array('SQL Error' => $error);
	}
	
	function DeleteEmployee($row, $id){
		$conn = GetConnection();
		$row2 = EscapeRow($row, $conn);
		$sql = "DELETE from WSP2012_Employee WHERE employee_id= '$row2[id]' ";
		$results = $conn -> query($sql);
		$error = $conn -> error;
		$conn -> close();	
		
		return $error == '' ? true : array('SQL Error' => $error);
	}
?>
